/*
 * @Author: youknowHRT 1021300769@qq.com
 * @Date: 2024-10-09 23:21:52
 * @LastEditors: youknowHRT 1021300769@qq.com
 * @LastEditTime: 2025-02-11 23:08:12
 * @FilePath: /jedi-admin-nest/src/custom.decorator.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import {
  createParamDecorator,
  ExecutionContext,
  SetMetadata,
} from '@nestjs/common';
import { Request } from 'express';

export const RequireLogin = () => SetMetadata('require-login', true);

export const UserInfo = createParamDecorator(
  (data: string, ctx: ExecutionContext) => {
    const request = ctx.switchToHttp().getRequest<Request>();
    if (!request.user) {
      return null;
    }

    return data ? request.user[data] : request.user;
  },
);
